import axios from 'axios'
import NProgress from "nprogress";
import router from "../router";

axios.defaults.baseURL = 'http://127.0.0.1:8888/admin/'
// 发起请求
axios.interceptors.request.use(config => {
    NProgress.start() // 开启进度条
    config.headers.Authorization = window.localStorage.getItem('token')
    return config
})

// 响应请求
axios.interceptors.response.use(
    config => {
    NProgress.done() // 关闭进度条
    if (config.data.code < 1000) {
        router.push('/login')
    }
    return config
},
    error => {
        alert(error)
        // router.push('/login')
    },
)

export default axios
